'use strict';
exports.main = async (event, context) => {
 //event为客户端上传的参数
 console.log('event : ', event)
 //获取数据库引用
 // const db = uniCloud.database();
 //获取表的引用
 // const tb = db.collection("goods");
 //一个给对象设置值的对象
 // const dbCmd =db.command;

 // console.log(">>>>>>>>>>>>>>>>>>", event.type)
 const dbJQL = uniCloud.databaseForJQL({ // 获取JQL database引用，此处需要传入云函数的event和context，必传
         event,
         context 
     })
const tb = dbJQL.collection('goods') 
 //根据类型进行操作
 switch (event.type) {
 
 case"show1":{    //查找轮播图并返回
 let {currentIndex}=event
  //查找
  let data;
  if(currentIndex===0){
    data= await tb.get()
	console.log(data)
  }else if(currentIndex===1){
	data = await tb.get()
  }else if(currentIndex===2){
	data = await tb.get() 
  }else{
	data = await tb.orderBy('collects_count desc').get()  
  }
  return {status:200,data:data}
 }
 };

};
